package com.spsy.prod.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spsy.common.log.annotation.Log;
import com.spsy.common.log.enums.BusinessType;
import com.spsy.common.security.annotation.RequiresPermissions;
import com.spsy.prod.domain.TbOrderDetail;
import com.spsy.prod.service.ITbOrderDetailService;
import com.spsy.common.core.web.controller.BaseController;
import com.spsy.common.core.web.domain.AjaxResult;
import com.spsy.common.core.utils.poi.ExcelUtil;
import com.spsy.common.core.web.page.TableDataInfo;

/**
 * 订单明细Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/prod")
public class TbOrderDetailController extends BaseController
{
    @Autowired
    private ITbOrderDetailService tbOrderDetailService;

    /**
     * 查询订单明细列表
     */
    @RequiresPermissions("prod:orderDetail:list")
    @GetMapping("/orderDetail/list")
    public TableDataInfo list(TbOrderDetail tbOrderDetail)
    {
        startPage();
        List<TbOrderDetail> list = tbOrderDetailService.selectTbOrderDetailList(tbOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出订单明细列表
     */
    @RequiresPermissions("prod:orderDetail:export")
    @Log(title = "订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/orderDetail/export")
    public void export(HttpServletResponse response, TbOrderDetail tbOrderDetail)
    {
        List<TbOrderDetail> list = tbOrderDetailService.selectTbOrderDetailList(tbOrderDetail);
        ExcelUtil<TbOrderDetail> util = new ExcelUtil<TbOrderDetail>(TbOrderDetail.class);
        util.exportExcel(response, list, "订单明细数据");
    }

    /**
     * 获取订单明细详细信息
     */
    @RequiresPermissions("prod:orderDetail:query")
    @GetMapping(value = "/orderDetail/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(tbOrderDetailService.selectTbOrderDetailByDetailId(detailId));
    }

    /**
     * 新增订单明细
     */
    @RequiresPermissions("prod:orderDetail:add")
    @Log(title = "订单明细", businessType = BusinessType.INSERT)
    @PostMapping(value = "/orderDetail/add")
    public AjaxResult add(@RequestBody TbOrderDetail tbOrderDetail)
    {
        return toAjax(tbOrderDetailService.insertTbOrderDetail(tbOrderDetail));
    }

    /**
     * 修改订单明细
     */
    @RequiresPermissions("prod:orderDetail:edit")
    @Log(title = "订单明细", businessType = BusinessType.UPDATE)
    @PutMapping("/orderDetail/edit")
    public AjaxResult edit(@RequestBody TbOrderDetail tbOrderDetail)
    {
        return toAjax(tbOrderDetailService.updateTbOrderDetail(tbOrderDetail));
    }

    /**
     * 删除订单明细
     */
    @RequiresPermissions("prod:orderDetail:remove")
    @Log(title = "订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/orderDetail/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(tbOrderDetailService.deleteTbOrderDetailByDetailIds(detailIds));
    }
}
